package _06_动态规划;

import java.util.Arrays;

/**
 * https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/
 * @Author: haogege
 * @Date: 2021/9/12
 */
public class _674_最长连续递增序列 {

    public static void main(String[] args) {

        int[] ints = {1, 3, 5, 4, 7};

        _674_最长连续递增序列 v = new _674_最长连续递增序列();
        System.out.println(v.findLengthOfLCIS(ints));

    }

    // 贪心
    public int findLengthOfLCIS(int[] nums) {
        if (nums.length == 1) return 1;
        int result = 1;
        int start = 0;

        for (int i = 0; i < nums.length; i++) {
            if (i > 0 && nums[i] <= nums[i - 1]) {
                start = i;
            }
            result = Math.max(result, i - start + 1);
        }
        return result;
    }

    // 动态规划
    public int findLengthOfLCIS1(int[] nums) {
        if (nums.length == 1) return 1;

        int[] dp = new int[nums.length];
        Arrays.fill(dp, 1);
        int max = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > nums[i - 1]) {
                dp[i] = dp[i - 1] + 1;
                max = Math.max(dp[i], max);
            }
        }
        return max;
    }


}
